﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;
using BusinessLogicLayer;

namespace ChamCong.NhanVien
{
    public partial class XemKetQuaLuong : BasePage
    {
        public static int _manv;
        protected void Page_Load(object sender, EventArgs e)
        {            
            _manv = Convert.ToInt32(Session["MaNV"]);
            if (!IsPostBack)
            {
                bindDdlYear();
                drNam.Items.FindByValue(DateTime.Now.Year.ToString()).Selected = true;
            }
        }

        protected void bindDdlYear()
        {
            for (int i = DateTime.Now.AddYears(1).Year; i >= 2010; i--)
            {
                ListItem obj = new ListItem();
                obj.Text = i.ToString();
                obj.Value = i.ToString();
                drNam.Items.Add(obj);
            }
        }

        protected void LoadReport(int _thang, int _nam, int _manv)
        {
            var source =
                new Microsoft.
                Reporting.
                WebForms.
                ReportDataSource("dsLuong", new CT_LuongThangBLL().LayBangLuongNV(_thang,_nam,_manv));

            repv.LocalReport.ReportPath = "Report/ReportKQLamViec.rdlc";
            repv.LocalReport.DataSources.Clear();
            repv.LocalReport.DataSources.Add(source);
            repv.LocalReport.Refresh();
        }

        protected void Nam_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _thang = int.Parse(drThang.SelectedValue);
            int _nam = int.Parse(drNam.SelectedValue);
            LoadReport(_thang, _nam, _manv);
        }

        protected void drThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _thang = int.Parse(drThang.SelectedValue);
            int _nam = int.Parse(drNam.SelectedValue);
            LoadReport(_thang, _nam, _manv);
        }
    }
}